package viewPackage.menus;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagLayout;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mainPackage.GFrame;
import mainPackage.GameMain;

public class NewGamePanel extends JPanel {
	
	private GFrame gameFrame;
	
	public NewGamePanel(GFrame frame) {
		super();
		this.gameFrame = frame;
		
		Graphics g = this.getGraphics();
		this.setBackground(Color.BLACK);
		
		MenuLabel menuTitle = new MenuLabel("Lost On Campus", 48);
		MenuLabel nameLabel = new MenuLabel("Please enter your name: ", 20);
		MenuLabel startGame = new MenuLabel("Start Game", 20);
		
		Font sansBold18 = new Font("SansSerif", Font.BOLD, 18);
		
		final JTextField name = new JTextField(20);
		name.setBorder(null);
		name.setBackground(Color.DARK_GRAY);
		name.setForeground(Color.YELLOW);
		name.setFont(sansBold18);
		name.setHorizontalAlignment(JTextField.CENTER);
		
		startGame.addMouseListener(new JLabelMouse(startGame) {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				gameFrame.getContentPane().removeAll();
				gameFrame.getContentPane().add(new GameMain(gameFrame, name.getText()), BorderLayout.CENTER);
				gameFrame.validate();
				gameFrame.repaint();
			}});
		
	
		GridBagLayout gbl = new GridBagLayout();
		this.setLayout(gbl);
		
		Constraints Ctitle = new Constraints(0,0,1,1,true);
		Constraints Cname = new Constraints(0,2,1,1,false);
		Constraints Ctext = new Constraints(0,3,1,1,false);
		Constraints Cstart = new Constraints(0,6,1,1,false);
		
		this.add(menuTitle, Ctitle);
		this.add(nameLabel, Cname);
		this.add(name, Ctext);
		this.add(startGame, Cstart);
		
		name.grabFocus();
		
	}
	
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
	}
	
}
